<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8">
    
    <title>Permuted Congruential Generator (64-bit, PCG64) &mdash; NumPy v1.18 Manual</title>
    
    <link rel="stylesheet" type="text/css" href="../../../_static/css/spc-bootstrap.css">
    <link rel="stylesheet" type="text/css" href="../../../_static/css/spc-extend.css">
    <link rel="stylesheet" href="../../../_static/scipy.css" type="text/css" >
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" >
    <link rel="stylesheet" href="../../../_static/graphviz.css" type="text/css" >
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../../',
        VERSION:     '1.18.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../../_static/language_data.js"></script>
    <script type="text/javascript" src="../../../_static/js/copybutton.js"></script>
    <link rel="author" title="About these documents" href="../../../about.html" >
    <link rel="index" title="Index" href="../../../genindex.html" >
    <link rel="search" title="Search" href="../../../search.html" >
    <link rel="top" title="NumPy v1.18 Manual" href="../../../index.html" >
    <link rel="up" title="Bit Generators" href="index.html" >
    <link rel="next" title="numpy.random.PCG64.state" href="generated/numpy.random.PCG64.state.html" >
    <link rel="prev" title="numpy.random.MT19937.ctypes" href="generated/numpy.random.MT19937.ctypes.html" > 
  </head>
  <body>
<div class="container">
  <div class="top-scipy-org-logo-header" style="background-color: #a2bae8;">
    <a href="../../../index.html">
      <img border=0 alt="NumPy" src="../../../_static/numpy_logo.png"></a>
    </div>
  </div>
</div>


    <div class="container">
      <div class="main">
        
	<div class="row-fluid">
	  <div class="span12">
	    <div class="spc-navbar">
              
    <ul class="nav nav-pills pull-left">
        <li class="active"><a href="https://numpy.org/">NumPy.org</a></li>
        <li class="active"><a href="https://numpy.org/doc">Docs</a></li>
        
        <li class="active"><a href="../../../index.html">NumPy v1.18 Manual</a></li>
        

          <li class="active"><a href="../../index.html" >NumPy Reference</a></li>
          <li class="active"><a href="../../routines.html" >Routines</a></li>
          <li class="active"><a href="../index.html" >Random sampling (<code class="xref py py-mod docutils literal notranslate"><span class="pre">numpy.random</span></code>)</a></li>
          <li class="active"><a href="index.html" accesskey="U">Bit Generators</a></li> 
    </ul>
              
              
    <ul class="nav nav-pills pull-right">
      <li class="active">
        <a href="../../../genindex.html" title="General Index"
           accesskey="I">index</a>
      </li>
      <li class="active">
        <a href="generated/numpy.random.PCG64.state.html" title="numpy.random.PCG64.state"
           accesskey="N">next</a>
      </li>
      <li class="active">
        <a href="generated/numpy.random.MT19937.ctypes.html" title="numpy.random.MT19937.ctypes"
           accesskey="P">previous</a>
      </li>
    </ul>
              
	    </div>
	  </div>
	</div>
        

	<div class="row-fluid">
      <div class="spc-rightsidebar span3">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Permuted Congruential Generator (64-bit, PCG64)</a><ul>
<li><a class="reference internal" href="#state">State</a></li>
<li><a class="reference internal" href="#parallel-generation">Parallel generation</a></li>
<li><a class="reference internal" href="#extending">Extending</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="generated/numpy.random.MT19937.ctypes.html"
                        title="previous chapter">numpy.random.MT19937.ctypes</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="generated/numpy.random.PCG64.state.html"
                        title="next chapter">numpy.random.PCG64.state</a></p>
<div id="searchbox" style="display: none" role="search">
  <h4>Quick search</h4>
    <div>
    <form class="search" action="../../../search.html" method="get">
      <input type="text" style="width: inherit;" name="q" />
      <input type="submit" value="search" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
          <div class="span9">
            
        <div class="bodywrapper">
          <div class="body" id="spc-section-body">
            
  <div class="section" id="permuted-congruential-generator-64-bit-pcg64">
<h1>Permuted Congruential Generator (64-bit, PCG64)<a class="headerlink" href="#permuted-congruential-generator-64-bit-pcg64" title="Permalink to this headline">¶</a></h1>
<dl class="class">
<dt id="numpy.random.PCG64">
<em class="property">class </em><code class="sig-prename descclassname">numpy.random.</code><code class="sig-name descname">PCG64</code><span class="sig-paren">(</span><em class="sig-param">seed_seq=None</em><span class="sig-paren">)</span><a class="headerlink" href="#numpy.random.PCG64" title="Permalink to this definition">¶</a></dt>
<dd><p>BitGenerator for the PCG-64 pseudo-random number generator.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>seed</strong><span class="classifier">{None, int, array_like[ints], SeedSequence}, optional</span></dt><dd><p>A seed to initialize the <a class="reference internal" href="generated/numpy.random.BitGenerator.html#numpy.random.BitGenerator" title="numpy.random.BitGenerator"><code class="xref py py-obj docutils literal notranslate"><span class="pre">BitGenerator</span></code></a>. If None, then fresh,
unpredictable entropy will be pulled from the OS. If an <code class="docutils literal notranslate"><span class="pre">int</span></code> or
<code class="docutils literal notranslate"><span class="pre">array_like[ints]</span></code> is passed, then it will be passed to
<a class="reference internal" href="generated/numpy.random.SeedSequence.html#numpy.random.SeedSequence" title="numpy.random.SeedSequence"><code class="xref py py-obj docutils literal notranslate"><span class="pre">SeedSequence</span></code></a> to derive the initial <a class="reference internal" href="generated/numpy.random.BitGenerator.html#numpy.random.BitGenerator" title="numpy.random.BitGenerator"><code class="xref py py-obj docutils literal notranslate"><span class="pre">BitGenerator</span></code></a> state. One may also
pass in a <a class="reference internal" href="generated/numpy.random.SeedSequence.html#numpy.random.SeedSequence" title="numpy.random.SeedSequence"><code class="xref py py-obj docutils literal notranslate"><span class="pre">SeedSequence</span></code></a> instance.</p>
</dd>
</dl>
</dd>
</dl>
<p class="rubric">Notes</p>
<p>PCG-64 is a 128-bit implementation of O’Neill’s permutation congruential
generator (<a class="reference internal" href="#r4523891264fe-1" id="id1">[1]</a>, <a class="reference internal" href="#r4523891264fe-2" id="id2">[2]</a>). PCG-64 has a period of <img class="math" src="../../../_images/math/91018ad7005c40f683c645b99dd28ae741d2de00.svg" alt="2^{128}"/> and supports
advancing an arbitrary number of steps as well as <img class="math" src="../../../_images/math/eff8c0727490d92520743ec0f4f745db2b9a8133.svg" alt="2^{127}"/> streams.
The specific member of the PCG family that we use is PCG XSL RR 128/64
as described in the paper (<a class="reference internal" href="#r4523891264fe-2" id="id3">[2]</a>).</p>
<p><code class="docutils literal notranslate"><span class="pre">PCG64</span></code> provides a capsule containing function pointers that produce
doubles, and unsigned 32 and 64- bit integers. These are not
directly consumable in Python and must be consumed by a <code class="docutils literal notranslate"><span class="pre">Generator</span></code>
or similar object that supports low-level access.</p>
<p>Supports the method <a class="reference internal" href="generated/numpy.random.PCG64.advance.html#numpy.random.PCG64.advance" title="numpy.random.PCG64.advance"><code class="xref py py-meth docutils literal notranslate"><span class="pre">advance</span></code></a> to advance the RNG an arbitrary number of
steps. The state of the PCG-64 RNG is represented by 2 128-bit unsigned
integers.</p>
<p><strong>State and Seeding</strong></p>
<p>The <code class="docutils literal notranslate"><span class="pre">PCG64</span></code> state vector consists of 2 unsigned 128-bit values,
which are represented externally as Python ints. One is the state of the
PRNG, which is advanced by a linear congruential generator (LCG). The
second is a fixed odd increment used in the LCG.</p>
<p>The input seed is processed by <a class="reference internal" href="generated/numpy.random.SeedSequence.html#numpy.random.SeedSequence" title="numpy.random.SeedSequence"><code class="xref py py-obj docutils literal notranslate"><span class="pre">SeedSequence</span></code></a> to generate both values. The
increment is not independently settable.</p>
<p><strong>Parallel Features</strong></p>
<p>The preferred way to use a BitGenerator in parallel applications is to use
the <a class="reference internal" href="generated/numpy.random.SeedSequence.spawn.html#numpy.random.SeedSequence.spawn" title="numpy.random.SeedSequence.spawn"><code class="xref py py-obj docutils literal notranslate"><span class="pre">SeedSequence.spawn</span></code></a> method to obtain entropy values, and to use these
to generate new BitGenerators:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">numpy.random</span> <span class="kn">import</span> <span class="n">Generator</span><span class="p">,</span> <span class="n">PCG64</span><span class="p">,</span> <span class="n">SeedSequence</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sg</span> <span class="o">=</span> <span class="n">SeedSequence</span><span class="p">(</span><span class="mi">1234</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rg</span> <span class="o">=</span> <span class="p">[</span><span class="n">Generator</span><span class="p">(</span><span class="n">PCG64</span><span class="p">(</span><span class="n">s</span><span class="p">))</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">sg</span><span class="o">.</span><span class="n">spawn</span><span class="p">(</span><span class="mi">10</span><span class="p">)]</span>
</pre></div>
</div>
<p><strong>Compatibility Guarantee</strong></p>
<p><code class="docutils literal notranslate"><span class="pre">PCG64</span></code> makes a guarantee that a fixed seed and will always produce
the same random integer stream.</p>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r4523891264fe-1"><span class="brackets"><a class="fn-backref" href="#id1">1</a></span></dt>
<dd><p><a class="reference external" href="http://www.pcg-random.org/">“PCG, A Family of Better Random Number Generators”</a></p>
</dd>
<dt class="label" id="r4523891264fe-2"><span class="brackets">2</span><span class="fn-backref">(<a href="#id2">1</a>,<a href="#id3">2</a>)</span></dt>
<dd><p>O’Neill, Melissa E. <a class="reference external" href="https://www.cs.hmc.edu/tr/hmc-cs-2014-0905.pdf">“PCG: A Family of Simple Fast Space-Efficient
Statistically Good Algorithms for Random Number Generation”</a></p>
</dd>
</dl>
</dd></dl>

<div class="section" id="state">
<h2>State<a class="headerlink" href="#state" title="Permalink to this headline">¶</a></h2>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.random.PCG64.state.html#numpy.random.PCG64.state" title="numpy.random.PCG64.state"><code class="xref py py-obj docutils literal notranslate"><span class="pre">state</span></code></a></p></td>
<td><p>Get or set the PRNG state</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="parallel-generation">
<h2>Parallel generation<a class="headerlink" href="#parallel-generation" title="Permalink to this headline">¶</a></h2>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.random.PCG64.advance.html#numpy.random.PCG64.advance" title="numpy.random.PCG64.advance"><code class="xref py py-obj docutils literal notranslate"><span class="pre">advance</span></code></a>(delta)</p></td>
<td><p>Advance the underlying RNG as-if delta draws have occurred.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.random.PCG64.jumped.html#numpy.random.PCG64.jumped" title="numpy.random.PCG64.jumped"><code class="xref py py-obj docutils literal notranslate"><span class="pre">jumped</span></code></a>([jumps])</p></td>
<td><p>Returns a new bit generator with the state jumped.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="extending">
<h2>Extending<a class="headerlink" href="#extending" title="Permalink to this headline">¶</a></h2>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.random.PCG64.cffi.html#numpy.random.PCG64.cffi" title="numpy.random.PCG64.cffi"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cffi</span></code></a></p></td>
<td><p>CFFI interface</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.random.PCG64.ctypes.html#numpy.random.PCG64.ctypes" title="numpy.random.PCG64.ctypes"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ctypes</span></code></a></p></td>
<td><p>ctypes interface</p></td>
</tr>
</tbody>
</table>
</div>
</div>


          </div>
        </div>
          </div>
        </div>
      </div>
    </div>

    <div class="container container-navbar-bottom">
      <div class="spc-navbar">
        
      </div>
    </div>
    <div class="container">
    <div class="footer">
    <div class="row-fluid">
    <ul class="inline pull-left">
      <li>
        &copy; Copyright 2008-2019, The SciPy community.
      </li>
      <li>
      Last updated on Feb 20, 2020.
      </li>
      <li>
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.4.2.
      </li>
    </ul>
    </div>
    </div>
    </div>
  </body>
</html>